﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>添加模板</title>
    <script type="text/javascript" src="../../../Content/highlighter/scripts/shCore.js"></script>
    <script type="text/javascript" src="../../../Content/highlighter/scripts/shBrushJScript.js"></script>
    <script type="text/javascript" src="../../../Content/highlighter/scripts/shBrushCSharp.js"></script>
    <script type="text/javascript" src="../../../Content/highlighter/scripts/shBrushXml.js"></script>
    <link type="text/css" rel="stylesheet" href="../../../Content/highlighter/styles/shCore.css" />
    <link type="text/css" rel="stylesheet" href="../../../Content/highlighter/styles/shCoreEclipse.css" />
    <script type="text/javascript">SyntaxHighlighter.all();</script>
</head>
<body>
    <h3>添加视图</h3>
    <p>
        1.在Controller文件夹上右击->添加->新建项...<br />
        <img src="../../../Content/images/rumen/20171123130448.png" /><br />
        2.Visual C#->NFinalRazorTemplate->修改名称-><br />
        <img src="../../../Content/images/rumen/20171124124109.png"/><br />
        3.这时VS会添加编辑文件和模板生成文件。<br />
        这个类似于aspx和aspx.cs文件的关系，一个用于设计，一个自动生成类文件。<br />
        也类似于winform和winfor.cs文件的关系，一个是设计视图，一个是代码视图。<br />
        <img src="../../../Content/images/rumen/20171124124642.png" />
        
    </p>
    Index1.cshtml内容如下：<br />
    <pre class="brush:js;html-script:true;">
    @inherits NFinal.View.RazorView&lt;string>
    &lt;!DOCTYPE html>
    &lt;html>
    &lt;head>
        &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        &lt;title>&lt;/title>
        &lt;meta http-equiv="Cache-Control" content="no-cache">
    &lt;/head>
    &lt;body>
    @Model
    &lt;/body>
    &lt;/html>
    </pre>
    Index1.tempalte.cs内容如下：<br />
    <pre class="brush:csharp;">
    using System;
    using System.IO;
    using System.Net;
    using System.Collections.Generic;
    using System.Threading.Tasks;
    using NFinal;

    //此代码由NFinalCompiler生成。
    //http://bbs.nfinal.com
    namespace NFinalWeb3.Views.Index
    {
        /// &lt;summary>
        /// 模板类
        /// &lt;/summary>
        [View("/NFinalWeb3/Views/Index/Index1.cshtml")]
        public class Index1 : NFinal.View.RazorView&lt;string>
        {
            /// &lt;summary>
            /// 模板类初始化函数
            /// &lt;/summary>
            /// &lt;param name="writer">写对象&lt;/param>
            /// &lt;param name="Model">数据&lt;/param>
            public Index1(NFinal.IO.Writer writer, string Model) : base(writer, Model)
            {
            }
            /// &lt;summary>
            /// 输出模板内容
            /// &lt;/summary>
            public override void Execute()
            {
                this.ExecuteAsync().Wait();
            }
            /// &lt;summary>
            /// 输出模板内容(异步)
            /// &lt;/summary>
            public override async Task ExecuteAsync()
            {
                await writer.WriteAsync("");
                await writer.WriteAsync("&lt;!DOCTYPE html>\r\n&lt;html>\r\n&lt;head>\r\n    &lt;meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\r\n    &lt;title>&lt;/title>\r\n\t&lt;meta http-equiv=\"Cache-Control\" content=\"no-cache\">\r\n&lt;/head>\r\n&lt;body>\r\n    ");
                await writer.WriteAsync(Model);
                await writer.WriteAsync("\r\n&lt;/body>\r\n&lt;/html>");
            }
        }
    }
    </pre>
    当你编辑cshtml文件时，template.cs文件会同步更新。
</body>
</html>